#ifndef CONTROLFORM_H
#define CONTROLFORM_H

#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QMap>

namespace Ui {
class ControlForm;
}

class ControlForm : public QWidget
{
    Q_OBJECT

public:
    explicit ControlForm(QWidget *parent = nullptr);
    ~ControlForm();

private:
    void handleSavePosClicked(QPushButton* clickedButton);
    Ui::ControlForm *ui;

    int m_speedXYLevel=0;
    int m_speedZLevel=0;
    double m_savedAbx = 0.0;
    double m_savedAby = 0.0;
    double m_savedAbz = 0.0;
    QMap<QPushButton*, QString> m_savedPosNames; // 保存按钮对应的名称

    void ShowLabelImage(QLabel *label,int level);
    void updateRelativePositions();
    void updateButtonStates(QPushButton *clickedButton);

private slots:
    void handleRenameClicked(const QString& newName);

public:
    void saveRelativePositionsToConfig();

protected:
    virtual void paintEvent(QPaintEvent*event) override;

private slots:
    void on_pushButton_minusXYSpeed_clicked();
    void on_pushButton_addXYSpeed_clicked();
    void on_pushButton_minusZSpeed_clicked();
    void on_pushButton_addZSpeed_clicked();
    void on_pushButton_execute_clicked();

    void updateLabel(int value);
    void handleDirectionKeyPressed(int direction);
    void on_pushButton_addZPos_clicked();
    void on_pushButton_minusZPos_clicked();
    void on_pushButton_relativeMove_clicked(bool checked);
    void on_pushButton_moveToAbsolutePos_clicked(bool checked);
    void on_pushButton_repositionToTheReferencePoint_clicked(bool checked);
    void on_pushButton_lockx_clicked(bool checked);
    void on_pushButton_locky_clicked(bool checked);
    void on_pushButton_lockz_clicked(bool checked);
    void on_pushButton_savePos1_clicked();
    void on_pushButton_savePos2_clicked();
    void on_pushButton_savePos3_clicked();

signals:
    void sig_labelChanged(const QString&);

};

#endif // CONTROLFORM_H
